home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / DINKDEMO / DC_SCRIB / DSCRIBBL.C next >
Text File  |  1992-05-17  |  2KB  |  81 lines

  1. // This is the class definition of DScribbleWind
  2.  
  3. #include "DScribbleWind.h"
  4. #include "DScribbleDoc.h"
  5.  
  6. Boolean DScribbleWind :: Init(DDocument *doc, Boolean hasColorWindows)
  7. {
  8.     Boolean inheritedSuccess;
  9.     PicHandle        thePict;
  10.  
  11.     thePict = ((DScribbleDoc *) doc)->fPict;
  12.     
  13.     fPenSize = 1;
  14.     fPenPat = patBlack;
  15.     
  16.     inheritedSuccess = inherited :: Init(doc, hasColorWindows);
  17.     if(thePict != NULL)
  18.     {
  19.         fVMin = 0;
  20.         fVMax = (**thePict).picFrame.bottom - (**thePict).picFrame.top;
  21.         
  22.         fHMin = 0;
  23.         fHMax = (**thePict).picFrame.right - (**thePict).picFrame.left;
  24.     }
  25.     Draw (&fWindowPtr->portRect);
  26.     return (inheritedSuccess);
  27. }// end of init function
  28.  
  29.  
  30. void    DScribbleWind :: DoContent(EventRecord* theEvent)
  31. {    
  32.     Rect contents;
  33.     Point    newPoint;
  34.     PicHandle thePict;
  35.     
  36.     FocusOnWindow();
  37.     GlobalToLocal(&theEvent->where);
  38.     GetContentRect(&contents);
  39.     if(PtInRect(theEvent->where, &contents))
  40.     {
  41.         PenSize(fPenSize, fPenSize);
  42.         
  43.         if(fPenPat == patBlack)
  44.             PenPat(black);
  45.         if(fPenPat == patGray)
  46.             PenPat(gray);
  47.         if(fPenPat == patWhite)
  48.             PenPat(white);
  49.         FocusOnContent();
  50.         GetMouse( &newPoint);
  51.         MoveTo(newPoint.h, newPoint.v);
  52.         do
  53.         {
  54.             GetMouse( &newPoint);
  55.                 LineTo(newPoint.h, newPoint.v);
  56.  
  57.         } while(StillDown());
  58.         
  59.         fDoc->fNeedToSave = TRUE;
  60.         thePict = ((DScribbleDoc *) fDoc)->fPict;
  61.         if( thePict != NULL)
  62.             KillPicture( thePict);
  63.             
  64.         thePict = OpenPicture(&fWindowPtr->portRect);
  65.         CopyBits(&fWindowPtr->portBits, &fWindowPtr->portBits,
  66.                 &fWindowPtr->portRect, &fWindowPtr->portRect, srcCopy, NULL);
  67.         ClosePicture();
  68.         ((DScribbleDoc *) fDoc)->fPict = thePict;
  69.     }// end if in content rect
  70.     else
  71.                 ScrollClick(theEvent);
  72.  
  73. }// end of DoContent function
  74.  
  75.  
  76. void    DScribbleWind :: Draw(Rect *r)
  77. {
  78.     if(((DScribbleDoc *) fDoc)->fPict != NULL)
  79.         DrawPicture(((DScribbleDoc *) fDoc)->fPict, &( (*(((DScribbleDoc *) fDoc)->fPict))->picFrame ) );
  80. }
  81.